/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bygf.dts.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
 *
 * @author pi
 */
public class MariaDB {
    private static Logger logger = LogManager.getLogger(MariaDB.class.getName());
   // The JDBC Connector Class.
    private static final String dbClassName = "org.mariadb.jdbc.Driver";
    // Connection string. emotherearth is the database the program
    // is connecting to. You can include user and password after this
    // by adding (say) ?user=paulr&password=paulr. Not recommended!
    private static final String CONNECTION =
                          "jdbc:mariadb://localhost:3306/DTS";
    public void connect() 
    {
        logger.debug(dbClassName);
        try {
            // Class.forName(xxx) loads the jdbc classes and
            // creates a drivermanager class factory
            Class.forName(dbClassName);
        } catch (ClassNotFoundException ex) {
            logger.error("ClassNotFoundException",ex);
        }
        // Properties for user and password. Here the user and password are both 'paulr'
        Properties p = new Properties();
        p.put("user","root");
        p.put("password","123456");
        // Now try to connect
        Connection c = null;
        try {
            c = DriverManager.getConnection(CONNECTION,p);
        } catch (SQLException ex) {
            logger.error("SQLException",ex);
        }
        System.out.println("It works !");
        try {
            c.close();
        } catch (SQLException ex) {
            logger.error("SQLException",ex);
        }
    }

}
